<template>
    <div class="addToCartSuccess">
        <common-header />
        <div class="successMain">
            <div class="successTop"><span class="succ-icon"></span><span class="addTitle">商品已成功加入购物车！</span></div>
            <div class="pItemMain">
                <span class="pItem">
                    <span><img width="60px" height="60px" style="border-radius: 1px" :src="image" /></span>
                    <span style="margin-left: 10px">
                        <div class="skuTitle">{{addCurSku.title}}</div>
                        <div>{{addCurSku.ownSpecDesc}}</div>
                    </span>
                </span>
                <span class="buttons">
                    <span class="viewProductDetial" @click="viewProductDetial">查看商品详情</span>
                    <span class="goCart" @click="viewCart">去购物车结算</span>
                </span>
            </div>
        </div>
        <common-footer />
    </div>
</template>
<script lang="ts">
    import { Component, Vue } from 'vue-property-decorator'
    import { Action, Getter } from 'vuex-class'
    import logo from '@/components/common/images/logo.png'
    import { namespace } from 'vuex-class';
    import Header from "@/components/portal-index/customer-portal/header/index.vue";
    import AddReceiverInfo from "@/components/portal-index/order-info/add-receiver-info.vue";
    import Footer from "@/components/portal-index/customer-portal/footer/index.vue";
    import CustomerApiActions from '@/components/api/customer-api-actions'
    import * as _ from 'lodash';
    const goodsName = namespace("goods");
    const cartName = namespace("cart");
    @Component({
        components: {
            CommonHeader: Header,
            CommonFooter: Footer
        }
    })
    export default class AddToCartSuccess extends Vue {
        public addCurSku: any = {};
        @cartName.State currentAddSkuId;
        public async created() {
            let apiActions = new CustomerApiActions(this);
            let result: any = await apiActions.getUserCart([]);
            let currentAddSkuId = this.currentAddSkuId;
            if (result.data.cartItems) {
                this.addCurSku = result.data.cartItems.find(item => item.skuId == currentAddSkuId);
            }
        }
        public viewProductDetial() {
            let id: any = this.addCurSku.spuId;
            this.$router.push({ path: '/detial', query: { id: id } });
        }
        public viewCart() {
            this.$router.push({ path: '/cart' });
        }
        public get image() {
            return this.addCurSku.images && this.addCurSku.images.split(',')[0];
        }

    }
</script>
<style lang="less">
    .addToCartSuccess {
        width: 100%;
        background-color: white;
        height: 100%;

        .successMain {
            height: 145px;
            background: #f5f5f5;
            margin-bottom: 20px;
            flex-direction: column;
            display: flex;
            align-items: center;

            .successTop {
                display: flex;
                flex-direction: row;
                margin-top: 20px;
                width: 75%;
            }

            .pItemMain {
                width: 75%;
                display: flex;
                justify-content: space-between;
                flex-direction: row;

                .buttons {
                    display: flex;
                    width: 300px;
                    align-items: flex-end;

                    .viewProductDetial {
                        background: #fff;
                        color: #E2231A;
                        border: 1px solid #fff;
                        width: 158px;
                        height: 36px;
                        display: flex;
                        justify-content: center;
                        cursor: pointer;
                        align-items: center;
                        font-size: 16px;
                        border-radius: 2px;
                        margin-bottom: 10px;
                    }

                    .goCart {
                        background: #E2231A;
                        border: 1px solid #E2231A;
                        color: #fff;
                        cursor: pointer;
                        width: 158px;
                        display: flex;
                        font-size: 16px;
                        height: 36px;
                        justify-content: center;
                        align-items: center;
                        margin-left: 20px;
                        border-radius: 2px;
                        margin-bottom: 10px;
                    }
                }
            }

            .buttons {
                width: 100px;
            }

            .pItem {
                display: flex;
                flex-direction: row;
                margin-top: 20px;

                .skuTitle {
                    width: 100%;
                    line-height: 28px;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                    font-family: "Microsoft YaHei";
                    font-size: 14px;
                    color: #333;
                }
            }

            .succ-icon {
                width: 25px;
                height: 25px;
                display: flex;
                overflow: hidden;
                background: url(//misc.360buyimg.com/user/cart/widget/addtocart-201608/i/addtocart-icons.png) 0 0 no-repeat;
            }

            .addTitle {
                margin-left: 10px;
                font-size: 18px;
                line-height: 25px;
                font-weight: 400;
                color: #71b247;
            }
        }
    }
</style>